package com.hqd.ch03.v25.spel.ast;

public class OpOr extends Operator {
    public OpOr(int startPos, int endPos, SpelNodeImpl... operands) {
        super("||", startPos, endPos, operands);
    }

    @Override
    protected Object getValueInternal(Object left, Object right) {
        Boolean lb = null;
        Boolean rb = null;
        if (left instanceof String) {
            lb = Boolean.parseBoolean((String) left);
        } else if (left instanceof Number) {
            lb = ((Number) left).intValue() == 0 ? false : true;
        } else if (left instanceof Boolean) {
            lb = (Boolean) left;
        }
        if (right instanceof String) {
            rb = Boolean.parseBoolean((String) right);
        } else if (right instanceof Number) {
            rb = ((Number) right).intValue() == 0 ? false : true;
        } else if (right instanceof Boolean) {
            rb = (Boolean) right;
        }
        if (lb == null && rb == null) {
            return true;
        }
        return lb || rb;
    }
}
